Week 1: Multi-threading with Java

 

This week's online activity is to get us started with Multi-threading with Java.  Multi-threading enables us to write programs that do more than one thing at a time.  This is especially important in Enterprise Programing because those programs have many simultaneous users and therefore must do many things simultaneously.

 

    To begin, watch the video on Lynda.com, in the Java Advanced Training course, Chapter 9, Working with Multi-Threading, 0:21:04s

URL: http://www.lynda.com/Java-tutorials/Extending-Thread-class/107061/113507-4.html

 

    Read the description of the Thread class in the Java 7 API documentation
    Read the description of the Runnable interface in the Java 7 API documentation
    Check your understanding of these new concepts with the online Blackboard Quiz for this activity



Question 1
What is the synchronized Java keyword used for?
	It is used to specify that a block of code runs simultaneously in more than one thread.
	It is used to specify that a block of code should be run in a separate thread
	It is used to merge two threads into one
	It is used to specify that a block of code (or a method) requires coordination between threads because otherwise it could result in problems if multiple threads execute it simultaneously (correct)

Question 2
What is Java Multi-threading?
	The ability to compile a Java program and run it on several different machines of different platforms without recompiling.	
	The process by which Java program code is converted into Java Byte Code that can be executed on a Java Virtual Machine
	Techniques that enable the Java programmer to arrange for multiple simultaneous threads of code execution in a single Java program. (correct)
	The sequence of error messages seen on the screen when something goes wrong with a program
	The process used to load programs consisting of multiple classes into a running Java Virtual Machine

Question 3
What is the only method declared by the Runnable interface?
	run (correct)
	thread
	start
	go
	newThread

Question 4
Which of the following Java statements could result in a useful additional Thread of execution?
	new Thread().run();
	new Thread(someRunnable).run();
	new Thread().start();
	Thread.run();
	new Thread(someRunnable).start(); (correct)

Question 5
We've seen two methods for creating a new Thread object: 1. passing an Object that implements the Runnable interface to the Thread constructor; and 2. instantiating an instance of a subclass of the Thread class. How should a programmer decide between the two methods?
	The programmer should just pick randomly between the two methods because there is no difference.
	If only the run method is being overridden, as is most often the case, a subclass of the Thread class should be used
	If the fundamental behavior of the Thread class is being changed by overridding several of its methods, the Runnable interface should be used
	If only the run method is being overridden, as is most often the case, the Runnable interface should be used (correct)
	The programmer should pick randomly between the two methods so that neither the Runnable interface nor the Thread class reserves get exhausted.